<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BAModelCooker
 *
 * @author jianfeng
 */
class BAModelCooker extends BCooker {

    //put your code here
    public static function getDynamicModel($itemData = null, $mediaIndex = NULL, $labelData = array(), $mediaType = 'string') {
        $model = new BDynamicFormModel();
        $fieldList = array();
        if (is_array($itemData)) {
            foreach ($itemData as $key => $value) {
                $label = isset($labelData[$key]) ? $labelData[$key] : $key;
                if ($mediaIndex != NULL) {
                    if ($mediaType == 'string') {
                        $fieldName = 'media_' . $key . '_' . $mediaIndex;
                        $fieldList[$key] = $fieldName;
                        $model->addField($fieldName, $value, $label);
                    }
                } else {
                    $model->addField($key, $value, $label);
                }
            }
        }

        return $model;
    }

    public static function getDynamicModelFieldList($itemData, $mediaIndex = NULL, $mediaType = 'string') {
        $fieldList = array();
        if (is_array($itemData)) {
            foreach ($itemData as $key => $value) {
                if ($mediaIndex != NULL) {
                    if ($mediaType == 'string') {
                        $fieldName = 'media_' . $key . '_' . $mediaIndex;
                        $fieldList[$key] = $fieldName;
                    }
                } else {
                    $fieldList[$key] = $key;
                }
            }
        }

        return $fieldList;
    }

}
